﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Mogre;
using MogreNewt;

namespace eqgen
{
    class Program
    {
        static void Main(string[] args)
        {
            Engine.Singleton.Initialise();
            Engine.Singleton.CurrentLevel = new Level();
            Engine.Singleton.CurrentLevel.SetGraphicsMesh("Level.mesh");
            Engine.Singleton.CurrentLevel.SetCollisionMesh("LevelCol.mesh");
            
            CharacterProfile profile = new CharacterProfile();
            profile.BodyMass = 70;
            profile.BodyScaleFactor = new Vector3(1.5f,1,1.5f);
            profile.HeadOffset = new Vector3(0, 0.8f, 0);
            profile.MeshName = "Man.mesh";
            profile.WalkSpeed = 1.0f;

            Character player = new Character(profile);
            player.SetPosition(new Vector3(0, 2, 0));
            Engine.Singleton.ObjectManager.Add(player);

            Engine.Singleton.GameCamera.Character = player;
            Engine.Singleton.GameCamera.Distance = 4;
            Engine.Singleton.GameCamera.Angle = new Degree(20);

            Light light = Engine.Singleton.SceneManager.CreateLight();
            light.Type = Light.LightTypes.LT_DIRECTIONAL;
            light.Direction = new Vector3(1, -3, 1).NormalisedCopy;
            light.DiffuseColour = new ColourValue(0.2f, 0.2f, 0.2f);

            Engine.Singleton.SceneManager.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_MODULATIVE;

            while (true)
            {
                Engine.Singleton.Update();

                if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_ESCAPE))
                    break;

                if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_LEFT))
                    player.Orientation *= Vector3.UNIT_Z.GetRotationTo(new Vector3(0.01f, 0, 1.0f).NormalisedCopy);
                if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_RIGHT))
                    player.Orientation *= Vector3.UNIT_Z.GetRotationTo(new Vector3(-0.01f, 0, 1.0f).NormalisedCopy);
                if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_UP))
                    player.State = Character.CharacterState.WALK;
                else
                    player.State = Character.CharacterState.IDLE;

                if (Engine.Singleton.Keyboard.IsKeyDown(MOIS.KeyCode.KC_F3))
                    Engine.Singleton.NewtonDebugger.ShowDebugInformation();
                else
                    Engine.Singleton.NewtonDebugger.HideDebugInformation();

            }
        }
    }
}
